<?php
class xl_languages{
    function list_lang(){
        global $dbh;
        $sql='SELECT * FROM languages ORDER BY lang_id DESC';
        $sth=$dbh->prepare($sql);
        $sth->execute();
        return $sth->fetchAll(PDO::FETCH_ASSOC);
    }
    function country_code(){
        global $dbh;
        $sql='SELECT * FROM country_code';
        $sth=$dbh->prepare($sql);
        $sth->execute();
        return $sth->fetchAll(PDO::FETCH_ASSOC);
    }
    function insert_lang($data){
        global $dbh;
        $sql='INSERT INTO languages(lang_code,title,keyword,description,status,day_time) VALUES(:lang_code,:title,:keyword,:description,:status,:day_time)';
        $sth=$dbh->prepare($sql);
        $sth->execute($data);
        return $sth;
    }
    function check_name_insert($lang_code){
        global $dbh;
        $sql='SELECT lang_code FROM languages WHERE lang_code=:lang_code LIMIT 0,1';
        $sth=$dbh->prepare($sql);
        $sth->execute(array(':lang_code'=>$lang_code));
        return $sth->fetch(PDO::FETCH_ASSOC);
    }
    function update_status($lang_id){
        global $dbh;
        $sql='UPDATE languages SET status=1-status WHERE lang_id=:lang_id';
        $sth=$dbh->prepare($sql);
        $sth->execute(array(':lang_id'=>$lang_id));
        return $sth;
    }
    function check_id($lang_id){
        global $dbh;
        $sql='SELECT lang_id FROM languages WHERE lang_id=:lang_id LIMIT 0,1';
        $sth=$dbh->prepare($sql);
        $sth->execute(array(':lang_id'=>$lang_id));
        return $sth->fetch(PDO::FETCH_ASSOC);
    }
    function check_lang($lang_code){
        global $dbh;
        $sql='SELECT lang_code FROM languages WHERE lang_code=:lang_code LIMIT 0,1';
        $sth=$dbh->prepare($sql);
        $sth->execute(array(':lang_code'=>$lang_code));
        return $sth->fetch(PDO::FETCH_ASSOC);
    }
    function delete_lang($lang_id){
        global $dbh;
        $sql='DELETE FROM languages WHERE lang_id=:lang_id';
        $sth=$dbh->prepare($sql);
        $sth->execute(array(':lang_id'=>$lang_id));
        return $sth;
    }
    function delete_all_lang($lang_id){
        global $dbh;
        $sql='SELECT * FROM languages WHERE lang_id=:lang_id';
        $sth=$dbh->prepare($sql);
        $sth->execute(array(':lang_id'=>$lang_id));
        return $sth->fetch(PDO::FETCH_ASSOC);
    }
    function show_table(){
        global $dbh;
        $sql='SHOW TABLES';
        $sth=$dbh->prepare($sql);
        $sth->execute();
        return $sth->fetchAll(PDO::FETCH_ASSOC);
    }
    function select_from($list_table){
        global $dbh;
        $sql="SELECT * FROM $list_table";
        $sth=$dbh->prepare($sql);
        $sth->execute();
        return $sth->fetchAll(PDO::FETCH_ASSOC);
    }
    function read_content_table($table,$id){
        global $dbh;
        $sql="SELECT * FROM $table WHERE id=:id LIMIT 0,1";
        $sth=$dbh->prepare($sql);
        $sth->execute(array(':id'=>$id));
        return $sth->fetch(PDO::FETCH_ASSOC);
    }
}